<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>class AboutYou::SDK::Query - RDoc Documentation</title>

<link href="../../fonts.css" rel="stylesheet">
<link href="../../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../../";
</script>

<script src="../../js/jquery.js"></script>
<script src="../../js/navigation.js"></script>
<script src="../../js/search_index.js"></script>
<script src="../../js/search.js"></script>
<script src="../../js/searcher.js"></script>
<script src="../../js/darkfish.js"></script>


<body id="top" role="document" class="class">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="../../index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="../../table_of_contents.html#pages">Pages</a>
    <a href="../../table_of_contents.html#classes">Classes</a>
    <a href="../../table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  <div id="class-metadata">
    
    <div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  
  <p class="link">Object
  
</div>

    <div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
  
  
    <li><a class="include" href="QueryBuilder.html">AboutYou::SDK::QueryBuilder</a>
  
  
  </ul>
</div>

    
    <!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    
    <li ><a href="#method-c-new">::new</a>
    
    <li ><a href="#method-i-check_response">#check_response</a>
    
    <li ><a href="#method-i-execute">#execute</a>
    
    <li ><a href="#method-i-execute_single">#execute_single</a>
    
    <li class="calls-super" ><a href="#method-i-fetch_autocomplete">#fetch_autocomplete</a>
    
    <li class="calls-super" ><a href="#method-i-fetch_basket">#fetch_basket</a>
    
    <li class="calls-super" ><a href="#method-i-fetch_facets">#fetch_facets</a>
    
    <li class="calls-super" ><a href="#method-i-fetch_product_search">#fetch_product_search</a>
    
    <li class="calls-super" ><a href="#method-i-fetch_products_by_eans">#fetch_products_by_eans</a>
    
    <li class="calls-super" ><a href="#method-i-fetch_products_by_ids">#fetch_products_by_ids</a>
    
    <li ><a href="#method-i-parse_result">#parse_result</a>
    
    <li ><a href="#method-i-query_string">#query_string</a>
    
    <li ><a href="#method-i-require_category_tree">#require_category_tree</a>
    
    <li ><a href="#method-i-require_facets">#require_facets</a>
    
  </ul>
</div>

  </div>
</nav>

<main role="main" aria-labelledby="class-AboutYou::SDK::Query">
  <h1 id="class-AboutYou::SDK::Query" class="class">
    class AboutYou::SDK::Query
  </h1>

  <section class="description">
    
<p>The <a href="Query.html">Query</a> class coordinates the building,
executing and parsing of one or multiple API-calls</p>
<dl class="rdoc-list note-list"><dt>Author
<dd>
<p>Collins GmbH &amp; Co KG</p>
</dd></dl>

  </section>

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    
    <section class="constants-list">
      <header>
        <h3>Constants</h3>
      </header>
      <dl>
      
        <dt id="QUERY_FACETS">QUERY_FACETS
        
        <dd><p>used for checking whether a query contains a facets-request or not</p>
        
      
        <dt id="QUERY_TREE">QUERY_TREE
        
        <dd><p>used for checking whether a query contains a category-request or not</p>
        
      
      </dl>
    </section>
    

    
    <section class="attribute-method-details" class="method-section">
      <header>
        <h3>Attributes</h3>
      </header>

      
      <div id="attribute-i-all_query" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">all_query</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>the actual query send to the api containing query and ghost-query</p>
        
        </div>
      </div>
      
      <div id="attribute-i-client" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">client</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>The Api-Client which performs the Api-Calls</p>
        
        </div>
      </div>
      
      <div id="attribute-i-factory" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">factory</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>the model factory which builds the models from the api-response</p>
        
        </div>
      </div>
      
      <div id="attribute-i-ghost_query" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">ghost_query</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>a helper-query used for fetching categories and/or facets if needed</p>
        
        </div>
      </div>
      
      <div id="attribute-i-mapping" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">mapping</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>a Hash containing the mapping for api_call_name =&gt;
method_name_in_model_factory</p>
        
        </div>
      </div>
      
      <div id="attribute-i-query" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">query</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>the query built by the app itself</p>
        
        </div>
      </div>
      
    </section>
    

    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Class Methods</h3>
       </header>

    
      <div id="method-c-new" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">new</span><span
            class="method-args">(client, factory)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>the Constructor for the <a href="Query.html">Query</a> class</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>client</code> -&gt; an instance of <a
href="Client.html">AboutYou::SDK::Client</a></p>
</li><li>
<p><code>factory</code> -&gt; an instance of <a
href="Factory/DefaultModelFactory.html">AboutYou::SDK::Factory::DefaultModelFactory</a></p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Query.html">AboutYou::SDK::Query</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/query.rb, line 41</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">client</span>, <span class="ruby-identifier">factory</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">client</span> = <span class="ruby-identifier">client</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">query</span> = []
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">ghost_query</span> = []
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">all_query</span> = []
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">factory</span> = <span class="ruby-identifier">factory</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">mapping</span> = {
    <span class="ruby-string">'autocompletion'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_autocomplete'</span>,
    <span class="ruby-string">'basket'</span>         =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_basket'</span>,
    <span class="ruby-string">'category'</span>       =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_categories_result'</span>,
    <span class="ruby-string">'category_tree'</span>  =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_category_tree'</span>,
    <span class="ruby-string">'facets'</span>         =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_facets_list'</span>,
    <span class="ruby-string">'facet'</span>          =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_facet_list'</span>,
    <span class="ruby-string">'facet_types'</span>    =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_facet_types'</span>,
    <span class="ruby-string">'products'</span>       =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_products_result'</span>,
    <span class="ruby-string">'products_eans'</span>  =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_products_ean_result'</span>,
    <span class="ruby-string">'product_search'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_product_search_result'</span>,
    <span class="ruby-string">'suggest'</span>        =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_suggest'</span>,
    <span class="ruby-string">'get_order'</span>      =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_order'</span>,
    <span class="ruby-string">'initiate_order'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'initiate_order'</span>,
    <span class="ruby-string">'child_apps'</span>     =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_child_apps'</span>,
    <span class="ruby-string">'live_variant'</span>   =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_variants_result'</span>,
    <span class="ruby-string">'did_you_mean'</span>   =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'create_spell_correction'</span>
  }
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Instance Methods</h3>
       </header>

    
      <div id="method-i-check_response" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">check_response</span><span
            class="method-args">(json_response)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>this method checks whether the api delievered a valid json-response or not</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>jsonResponse</code> -&gt; the plain json received from the api</p>
</li></ul>
</li><li>
<p><strong>Fails</strong> :</p>
<ul><li>
<p>if the response is false, not an array or has a different amount of
subresponses then requests</p>
</li><li>
<p>if there is any subresponse which was not requested</p>
</li><li>
<p>if there is no model factory mapping for a subresponse</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="check_response-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/query.rb, line 270</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">check_response</span>(<span class="ruby-identifier">json_response</span>)
  <span class="ruby-identifier">fail</span> <span class="ruby-string">'UnexpectedResultException!'</span> <span class="ruby-keyword">if</span>
  <span class="ruby-identifier">json_response</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">false</span> <span class="ruby-operator">||</span>
  <span class="ruby-operator">!</span><span class="ruby-identifier">json_response</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-operator">||</span>
  <span class="ruby-identifier">json_response</span>.<span class="ruby-identifier">count</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">all_query</span>.<span class="ruby-identifier">count</span>

  (<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-identifier">json_response</span>.<span class="ruby-identifier">count</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">current_query</span> = <span class="ruby-identifier">all_query</span>[<span class="ruby-identifier">index</span>]
    <span class="ruby-identifier">response_key</span>  = <span class="ruby-identifier">json_response</span>[<span class="ruby-identifier">index</span>].<span class="ruby-identifier">keys</span>[<span class="ruby-value">0</span>]
    <span class="ruby-identifier">query_key</span>     = <span class="ruby-identifier">current_query</span>.<span class="ruby-identifier">keys</span>[<span class="ruby-value">0</span>]

    <span class="ruby-identifier">fail</span> <span class="ruby-string">'UnexpectedResultException! result '</span> <span class="ruby-operator">+</span> <span class="ruby-constant">String</span>(<span class="ruby-identifier">query_key</span>) <span class="ruby-operator">+</span>
      <span class="ruby-string">' expected, but '</span> <span class="ruby-operator">+</span> <span class="ruby-constant">String</span>(<span class="ruby-identifier">response_key</span>) <span class="ruby-operator">+</span> <span class="ruby-string">' given on position '</span> <span class="ruby-operator">+</span>
      <span class="ruby-constant">String</span>(<span class="ruby-identifier">index</span>) <span class="ruby-operator">+</span> <span class="ruby-string">' - query: '</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">current_query</span>.<span class="ruby-identifier">to_json</span> <span class="ruby-keyword">if</span>
    <span class="ruby-identifier">response_key</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">query_key</span>

    <span class="ruby-identifier">fail</span> <span class="ruby-string">'UnexpectedResultException! '</span> <span class="ruby-operator">+</span> <span class="ruby-constant">String</span>(<span class="ruby-identifier">response_key</span>) <span class="ruby-operator">+</span>
      <span class="ruby-string">' is unknown result'</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">mapping</span>.<span class="ruby-identifier">key?</span> <span class="ruby-identifier">response_key</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-execute" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">execute</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>requests all of the queries and returns the parsed api-response</p>
<ul><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>an Array containing all of the models build with the data of the api</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="execute-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/query.rb, line 243</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">execute</span>
  <span class="ruby-keyword">return</span> [] <span class="ruby-keyword">if</span> <span class="ruby-identifier">query</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">ghost_query</span>.<span class="ruby-identifier">empty?</span>
  <span class="ruby-identifier">parse_result</span>(<span class="ruby-identifier">client</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">query_string</span>), <span class="ruby-identifier">query</span>.<span class="ruby-identifier">count</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-execute_single" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">execute_single</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>requests all of the queries and returns only the first parsed api-response</p>
<ul><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>the first model build with the data of the api</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="execute_single-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/query.rb, line 254</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">execute_single</span>
  <span class="ruby-identifier">execute</span>[<span class="ruby-value">-1</span>]
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-fetch_autocomplete" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">fetch_autocomplete</span><span
            class="method-args">(searchword, limit = nil, types = nil)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>wrapper-method for <a
href="Query.html#method-i-fetch_autocomplete">#fetch_autocomplete</a> which
coordinates Category- and Facet-Manager</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>searchword</code> -&gt; a String containing the word to search
completitions for</p>
</li><li>
<p><code>limit</code> -&gt; Maximum number of results [optional]</p>
</li><li>
<p><code>types</code> -&gt; Array of types to search for [optional]</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Query.html">AboutYou::SDK::Query</a></p>
</li></ul>
</li></ul>
          
          
            <div class="method-calls-super">
              Calls superclass method
              <a href="QueryBuilder.html#method-i-fetch_autocomplete">AboutYou::SDK::QueryBuilder#fetch_autocomplete</a>
            </div>
          

          
          <div class="method-source-code" id="fetch_autocomplete-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/query.rb, line 78</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">fetch_autocomplete</span>(<span class="ruby-identifier">searchword</span>, <span class="ruby-identifier">limit</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">types</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">super</span>(<span class="ruby-identifier">searchword</span>, <span class="ruby-identifier">limit</span>, <span class="ruby-identifier">types</span>)

  <span class="ruby-identifier">require_category_tree</span>
  <span class="ruby-identifier">require_facets</span>

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-fetch_basket" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">fetch_basket</span><span
            class="method-args">(session_id)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>wrapper-method for <a
href="Query.html#method-i-fetch_basket">#fetch_basket</a> which coordinates
Category- and Facet-Manager</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>session_id</code> -&gt; a String containing the session id of an user</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Query.html">AboutYou::SDK::Query</a></p>
</li></ul>
</li></ul>
          
          
            <div class="method-calls-super">
              Calls superclass method
              <a href="QueryBuilder.html#method-i-fetch_basket">AboutYou::SDK::QueryBuilder#fetch_basket</a>
            </div>
          

          
          <div class="method-source-code" id="fetch_basket-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/query.rb, line 96</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">fetch_basket</span>(<span class="ruby-identifier">session_id</span>)
  <span class="ruby-keyword">super</span>(<span class="ruby-identifier">session_id</span>)

  <span class="ruby-identifier">require_category_tree</span>
  <span class="ruby-identifier">require_facets</span>

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-fetch_facets" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">fetch_facets</span><span
            class="method-args">(group_ids = [])</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          
          
          
            <div class="method-calls-super">
              Calls superclass method
              <a href="QueryBuilder.html#method-i-fetch_facets">AboutYou::SDK::QueryBuilder#fetch_facets</a>
            </div>
          

          
          <div class="method-source-code" id="fetch_facets-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/query.rb, line 105</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">fetch_facets</span>(<span class="ruby-identifier">group_ids</span> = [])
  <span class="ruby-keyword">super</span>(<span class="ruby-identifier">group_ids</span>)

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-fetch_product_search" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">fetch_product_search</span><span
            class="method-args">(criteria)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>wrapper-method for <a
href="Query.html#method-i-fetch_product_search">#fetch_product_search</a>
which coordinates Category- and Facet-Manager</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>criteria</code> -&gt; Hash containing one or multiple search terms</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Query.html">AboutYou::SDK::Query</a></p>
</li></ul>
</li></ul>
          
          
            <div class="method-calls-super">
              Calls superclass method
              <a href="QueryBuilder.html#method-i-fetch_product_search">AboutYou::SDK::QueryBuilder#fetch_product_search</a>
            </div>
          

          
          <div class="method-source-code" id="fetch_product_search-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/query.rb, line 162</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">fetch_product_search</span>(<span class="ruby-identifier">criteria</span>)
  <span class="ruby-keyword">super</span>(<span class="ruby-identifier">criteria</span>)

  <span class="ruby-identifier">require_category_tree</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">criteria</span>.<span class="ruby-identifier">requires_categories</span>
  <span class="ruby-identifier">require_facets</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">criteria</span>.<span class="ruby-identifier">requires_facets</span>

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-fetch_products_by_eans" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">fetch_products_by_eans</span><span
            class="method-args">(eans, fields = [])</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>wrapper-method for <a
href="Query.html#method-i-fetch_products_by_eans">#fetch_products_by_eans</a>
which coordinates Category- and Facet-Manager</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>eans</code> -&gt; Either a single ean or an Array of eans which
should be fetched</p>
</li><li>
<p><code>fields</code> -&gt; Additional product fields which should be fetched
for each product [optional]</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Query.html">AboutYou::SDK::Query</a></p>
</li></ul>
</li></ul>
          
          
            <div class="method-calls-super">
              Calls superclass method
              <a href="QueryBuilder.html#method-i-fetch_products_by_eans">AboutYou::SDK::QueryBuilder#fetch_products_by_eans</a>
            </div>
          

          
          <div class="method-source-code" id="fetch_products_by_eans-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/query.rb, line 142</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">fetch_products_by_eans</span>(<span class="ruby-identifier">eans</span>, <span class="ruby-identifier">fields</span> = [])
  <span class="ruby-keyword">super</span>(<span class="ruby-identifier">eans</span>, <span class="ruby-identifier">fields</span>)

  <span class="ruby-identifier">require_category_tree</span> <span class="ruby-keyword">if</span>
  <span class="ruby-constant">AboutYou</span><span class="ruby-operator">::</span><span class="ruby-constant">SDK</span><span class="ruby-operator">::</span><span class="ruby-constant">Criteria</span><span class="ruby-operator">::</span><span class="ruby-constant">ProductFields</span>.<span class="ruby-identifier">requires_categories</span>(<span class="ruby-identifier">fields</span>)
  <span class="ruby-identifier">require_facets</span> <span class="ruby-keyword">if</span>
  <span class="ruby-constant">AboutYou</span><span class="ruby-operator">::</span><span class="ruby-constant">SDK</span><span class="ruby-operator">::</span><span class="ruby-constant">Criteria</span><span class="ruby-operator">::</span><span class="ruby-constant">ProductFields</span>.<span class="ruby-identifier">requires_facets</span>(<span class="ruby-identifier">fields</span>)

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-fetch_products_by_ids" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">fetch_products_by_ids</span><span
            class="method-args">(ids, fields = [])</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>wrapper-method for <a
href="Query.html#method-i-fetch_products_by_ids">#fetch_products_by_ids</a>
which coordinates Category- and Facet-Manager</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>ids</code> -&gt; Either a single id or an Array of ids which should
be fetched</p>
</li><li>
<p><code>fields</code> -&gt; Additional product fields which should be fetched
for each product [optional]</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Query.html">AboutYou::SDK::Query</a></p>
</li></ul>
</li></ul>
          
          
            <div class="method-calls-super">
              Calls superclass method
              <a href="QueryBuilder.html#method-i-fetch_products_by_ids">AboutYou::SDK::QueryBuilder#fetch_products_by_ids</a>
            </div>
          

          
          <div class="method-source-code" id="fetch_products_by_ids-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/query.rb, line 121</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">fetch_products_by_ids</span>(<span class="ruby-identifier">ids</span>, <span class="ruby-identifier">fields</span> = [])
  <span class="ruby-keyword">super</span>(<span class="ruby-identifier">ids</span>, <span class="ruby-identifier">fields</span>)

  <span class="ruby-identifier">require_category_tree</span> <span class="ruby-keyword">if</span>
  <span class="ruby-constant">AboutYou</span><span class="ruby-operator">::</span><span class="ruby-constant">SDK</span><span class="ruby-operator">::</span><span class="ruby-constant">Criteria</span><span class="ruby-operator">::</span><span class="ruby-constant">ProductFields</span>.<span class="ruby-identifier">requires_categories</span>(<span class="ruby-identifier">fields</span>)
  <span class="ruby-identifier">require_facets</span> <span class="ruby-keyword">if</span>
  <span class="ruby-constant">AboutYou</span><span class="ruby-operator">::</span><span class="ruby-constant">SDK</span><span class="ruby-operator">::</span><span class="ruby-constant">Criteria</span><span class="ruby-operator">::</span><span class="ruby-constant">ProductFields</span>.<span class="ruby-identifier">requires_facets</span>(<span class="ruby-identifier">fields</span>)

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-parse_result" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">parse_result</span><span
            class="method-args">(json_response, is_multi_request = true)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>parses the plain json result from the api and calls the respective
modelfactory methods for building the models for the json resposne</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>jsonResponse</code> -&gt; the plain json received from the api</p>
</li><li>
<p><code>isMultiRequest</code> -&gt; boolean which determines whether the
request has more then one query or not [optional]</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>an Array containing all models build from the modelfactory</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="parse_result-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/query.rb, line 302</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">parse_result</span>(<span class="ruby-identifier">json_response</span>, <span class="ruby-identifier">is_multi_request</span> = <span class="ruby-keyword">true</span>)
  <span class="ruby-identifier">check_response</span>(<span class="ruby-identifier">json_response</span>)
  <span class="ruby-identifier">results</span> = []
  <span class="ruby-identifier">query_ids</span> = []

  <span class="ruby-identifier">all_query</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">query</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">query_ids</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">query</span>.<span class="ruby-identifier">keys</span>[<span class="ruby-value">0</span>])
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">json_response</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">response_object</span>, <span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">current_query</span>   = <span class="ruby-identifier">all_query</span>[<span class="ruby-identifier">index</span>]
    <span class="ruby-identifier">result_key</span>      = <span class="ruby-identifier">response_object</span>.<span class="ruby-identifier">keys</span>[<span class="ruby-value">0</span>]
    <span class="ruby-identifier">json_object</span>     = <span class="ruby-identifier">response_object</span>[<span class="ruby-identifier">result_key</span>]
    <span class="ruby-identifier">query_key</span>       = <span class="ruby-identifier">current_query</span>.<span class="ruby-identifier">keys</span>[<span class="ruby-value">0</span>]
    <span class="ruby-identifier">factory</span>         = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">factory</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">json_object</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">json_object</span>[<span class="ruby-string">'error_code'</span>]
      <span class="ruby-identifier">result</span> = <span class="ruby-identifier">factory</span>.<span class="ruby-identifier">pre_handle_error</span>(
        <span class="ruby-identifier">json_object</span>,
        <span class="ruby-identifier">result_key</span>,
        <span class="ruby-identifier">is_multi_request</span>
      )

      <span class="ruby-keyword">if</span> <span class="ruby-identifier">result</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword">false</span>
        <span class="ruby-identifier">results</span>.<span class="ruby-identifier">push</span>(
          <span class="ruby-identifier">result_key</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">result</span>
        )
        <span class="ruby-keyword">next</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-identifier">query</span>    = <span class="ruby-identifier">current_query</span>[<span class="ruby-identifier">query_key</span>]
    <span class="ruby-identifier">query_id</span> = <span class="ruby-identifier">query_ids</span>[<span class="ruby-identifier">index</span>]
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">query_id</span> <span class="ruby-operator">==</span> <span class="ruby-constant">QUERY_FACETS</span>
      <span class="ruby-identifier">factory</span>.<span class="ruby-identifier">update_facet_manager</span>(<span class="ruby-identifier">json_object</span>, <span class="ruby-identifier">query</span>)
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">query_id</span> <span class="ruby-operator">==</span> <span class="ruby-constant">QUERY_TREE</span>
      <span class="ruby-identifier">factory</span>.<span class="ruby-identifier">initialize_category_manager</span>(<span class="ruby-identifier">json_object</span>)
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">method</span> = <span class="ruby-identifier">mapping</span>[<span class="ruby-identifier">result_key</span>]
      <span class="ruby-identifier">result</span> = <span class="ruby-identifier">factory</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">json_object</span>, <span class="ruby-identifier">query</span>)
      <span class="ruby-identifier">results</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">result</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">results</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-query_string" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">query_string</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>the methods builds the complete query string which represents the body of
the api call</p>
<ul><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>JSON-String containing all queries which need to be executed</p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="query_string-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/query.rb, line 223</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">query_string</span>
  <span class="ruby-identifier">result</span> = []

  <span class="ruby-identifier">ghost_query</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ghost_query</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">result</span>.<span class="ruby-identifier">push</span>(
      <span class="ruby-identifier">ghost_query</span>[<span class="ruby-identifier">ghost_query</span>.<span class="ruby-identifier">keys</span>[<span class="ruby-value">0</span>]]
    ) <span class="ruby-keyword">if</span> <span class="ruby-identifier">ghost_query</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">all_query</span> = <span class="ruby-identifier">result</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">query</span>

  (<span class="ruby-identifier">result</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">query</span>).<span class="ruby-identifier">to_json</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-require_category_tree" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">require_category_tree</span><span
            class="method-args">(fetch_forced = false)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>this method checks whether it is neccessary for the query to get the
category-tree from the api</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>fetchForced</code> -&gt; determines whether the requirance of the
category tree is forced</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Query.html">AboutYou::SDK::Query</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="require_category_tree-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/query.rb, line 180</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">require_category_tree</span>(<span class="ruby-identifier">fetch_forced</span> = <span class="ruby-keyword">false</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span> <span class="ruby-keyword">unless</span>

  <span class="ruby-identifier">fetch_forced</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">factory</span>.<span class="ruby-identifier">category_manager</span>.<span class="ruby-identifier">empty?</span>

  <span class="ruby-identifier">ghost_query</span>.<span class="ruby-identifier">push</span>(
    <span class="ruby-constant">QUERY_TREE</span> =<span class="ruby-operator">&gt;</span> {
      <span class="ruby-string">'category_tree'</span> =<span class="ruby-operator">&gt;</span> {
        <span class="ruby-string">'version'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'2'</span>
      }
    }
  )

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-require_facets" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">require_facets</span><span
            class="method-args">(fetch_forced = false)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>this method checks whether it is neccessary for the query to get the facets
from the api</p>
<ul><li>
<p><strong>Args</strong>    :</p>
<ul><li>
<p><code>fetchForced</code> -&gt; determines whether the requirance of the
facets is forced</p>
</li></ul>
</li><li>
<p><strong>Returns</strong> :</p>
<ul><li>
<p>Instance of <a href="Query.html">AboutYou::SDK::Query</a></p>
</li></ul>
</li></ul>
          
          

          
          <div class="method-source-code" id="require_facets-source">
            <pre><span class="ruby-comment"># File lib/AboutYou/query.rb, line 205</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">require_facets</span>(<span class="ruby-identifier">fetch_forced</span> = <span class="ruby-keyword">false</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">fetch_forced</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">factory</span>.<span class="ruby-identifier">facet_manager</span>.<span class="ruby-identifier">empty?</span>

  <span class="ruby-identifier">ghost_query</span>.<span class="ruby-identifier">push</span>(
    <span class="ruby-constant">QUERY_FACETS</span> =<span class="ruby-operator">&gt;</span> {
      <span class="ruby-string">'facets'</span> =<span class="ruby-operator">&gt;</span> {}
    }
  )

  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
  </section>
</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="http://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.2.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>

